package com.nzx.business.user.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.nzx.business.user.vo.QueryUserPageVo;
import com.nzx.common.exception.BizException;
import com.nzx.common.result.ApiResult;
import com.nzx.common.result.ResultCommon;
import com.nzx.business.user.entity.User;
import com.nzx.business.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 类描述：用户信息管理接口
 *
 * @author niezhuxe
 * @date 2021/11/3 23:49
 */
@Slf4j
@RestController
@RequestMapping("/api/business/user/")
@Api(tags = "用户信息管理接口")
public class UserController {

    @Autowired
    private UserService userService;


    @GetMapping("/listPage")
    @ApiOperation(value = "获取信息",httpMethod = "GET")
    public ApiResult<Page<User>> listPage(@RequestBody QueryUserPageVo pageVo){

        Page<User> page = new Page<>(pageVo.getPage(),pageVo.getLimit());
        //userService.listPage(pageVo,page);
        return ResultCommon.doSuccess();
    }

    @GetMapping("/message")
    @ApiOperation(value = "获取信息",httpMethod = "GET")
    public ApiResult getMessage(){

        log.info("Hello World!");
        return ResultCommon.doSuccess();
    }

    @GetMapping("/detail")
    @ApiOperation(value = "用户详情",httpMethod = "GET")
    public ApiResult<User> queryUserDetail(@RequestParam("id") Integer id) throws Exception{

        if(id >10){
            throw new BizException("数据超过大小");
        }
        return ResultCommon.doSuccess(userService.queryUserDetail(id));
    }
}
